package cipher

import (
	"gitee.com/micro-plat/sas/sas/modules/const/enum"
	"gitee.com/micro-plat/sas/sas/modules/secret"
	"github.com/micro-plat/hydra"
)

//EnableHandler .
type EnableHandler struct {
	sLib secret.ISecret
}

//NewEnableHandler .
func NewEnableHandler() (u *EnableHandler) {
	return &EnableHandler{

		sLib: secret.NewSecret(),
	}
}

// Handle 启用密钥
func (o *EnableHandler) Handle(ctx hydra.IContext) (r interface{}) {
	ctx.Log().Debug("------启用密钥------")
	ctx.Log().Debug("1.检查参数")
	if err := ctx.Request().Check("euid"); err != nil {
		return err
	}

	if err := enum.CheckType(ctx.Request().Path().Params().GetString("type")); err != nil {
		return err
	}

	ctx.Log().Debug("2.启用密钥")
	res, err := o.sLib.Enable(
		ctx.Request().GetString("euid"),
		ctx.Request().Path().Params().GetString("type"))
	if err != nil {
		return err
	}

	return res
}
